﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Engine.Classes {
    import flash.events.*;
    import flash.display.*;
    import flash.geom.*;
    import Engine.Helpers.*;
    import flash.filters.*;
    import Engine.*;

	/**
	 *	相比EngineObject, 多了坐标、显示对象，以及相关坐标位置的判断逻辑 
	 * 
	 */
    public class PositionedObject extends EngineObject {

        protected var m_objectType:int = 1;
        protected var m_objectFlags:int = 0;
        protected var m_position:Vector3;
        protected var m_screenPosition:Point;
        protected var m_size:Vector3;
        protected var m_displayObject:DisplayObject = null;
        protected var m_displayObjectDirty:Boolean = false;
        protected var m_transformDirty:Boolean = false;
        protected var m_visible:Boolean = true;
        protected var m_attachPosition:Vector3 = null;
        protected var m_attachSize:Vector3 = null;
        protected var m_highlighted:Boolean;
        protected var m_culled:Boolean;
        protected var m_endPosition:Vector3;

        public function PositionedObject():void{
            this.m_position = new Vector3();
            this.m_size = new Vector3();
            this.m_endPosition = new Vector3();
            super();
        }
        public function isPickable():Boolean{
            return (true);
        }
        override public function getSaveObject():Object{
            var _local1:Object = super.getSaveObject();
            _local1.position = this.m_position;
            return (_local1);
        }
        override public function loadObject(_arg1:Object):void{
            super.loadObject(_arg1);
            this.m_position = new Vector3(_arg1.position.x, _arg1.position.y, _arg1.position.z);
        }
        public function getObjectType():int{
            return (this.m_objectType);
        }
        public function getReference():PositionedObject{
            return (this);
        }
        public function checkObjectType(_arg1:uint):Boolean{
            return (((this.m_objectType & _arg1) > 0));
        }
        public function checkObjectFlags(_arg1:uint, _arg2:Boolean=true):Boolean{
            if (_arg2){
                return (((this.m_objectFlags & _arg1) == _arg1));
            };
            return (((this.m_objectFlags & _arg1) > 0));
        }
        public function getPosition():Vector3{
            return (this.m_position.clone());
        }
        public function getPositionNoClone():Vector3{
            return (this.m_position);
        }
        public function getEndPosition():Vector3{
            this.m_endPosition.x = (this.m_position.x + this.m_size.x);
            this.m_endPosition.y = (this.m_position.y + this.m_size.y);
            this.m_endPosition.z = (this.m_position.z + this.m_size.z);
            return (this.m_endPosition);
        }
        public function getScreenPosition():Point{
            return (this.m_screenPosition.clone());
        }
        public function getSizeNoClone():Vector3{
            return (this.m_size);
        }
        public function getSize():Vector3{
            return (this.m_size.clone());
        }
        public function getBoundingBox():Box3D{
            return (new Box3D(this.m_position, this.m_size));
        }
        public function isWithinViewport():Boolean{
            var _local2:Rectangle;
            var _local1:Boolean;
            if (this.m_displayObject){
                _local1 = true;
                _local2 = this.m_displayObject.getRect(GlobalEngine.viewport);
                if ((((((((0 >= _local2.right)) || ((0 >= _local2.bottom)))) || ((GlobalEngine.stage.stageWidth <= _local2.x)))) || ((GlobalEngine.stage.stageHeight <= _local2.y)))){
                    _local1 = false;
                };
            };
            return (_local1);
        }
        public function isPixelInside(_arg1:Point):Boolean{
            var _local2:Boolean;
            if (this.m_displayObject){
                if (this.m_displayObject.getRect(this.m_displayObject.parent).containsPoint(_arg1)){
                    _local2 = true;
                };
            };
            return (_local2);
        }
        public function isWithinBounds(_arg1:PositionedObject):Boolean{
            var _local2:Vector3 = this.getPosition();
            var _local3:Vector3 = this.getEndPosition();
            var _local4:Vector3 = _arg1.getPosition();
            var _local5:Vector3 = _arg1.getEndPosition();
            return ((((((((_local2.x <= _local4.x)) && ((_local2.y <= _local4.y)))) && ((_local3.x >= _local5.x)))) && ((_local3.y >= _local5.y))));
        }
        public function updateCulling():void{
            this.m_culled = (this.isWithinViewport() == false);
            this.setVisible(this.m_visible);
        }
        public function setVisible(_arg1:Boolean):void{
            this.m_visible = _arg1;
            if (this.m_displayObject){
                this.m_displayObject.visible = ((_arg1) && ((this.m_culled == false)));
            };
        }
        public function isVisible():Boolean{
            return (((this.m_visible) && ((this.m_culled == false))));
        }
        public function set alpha(_arg1:Number):void{
            if (this.m_displayObject){
                this.m_displayObject.alpha = _arg1;
            };
        }
        public function get alpha():Number{
            var _local1:Number = 1;
            if (this.m_displayObject){
                _local1 = this.m_displayObject.alpha;
            };
            return (_local1);
        }
        public function setPosition(_arg1:Number, _arg2:Number, _arg3:Number=0):void{
            var _local4:Vector3;
            if (((((!((this.m_position.x == _arg1))) || (!((this.m_position.y == _arg2))))) || (!((this.m_position.z == _arg3))))){
                _local4 = new Vector3((_arg1 - this.m_position.x), (_arg2 - this.m_position.y), (_arg3 - this.m_position.z));
                this.m_position = new Vector3(_arg1, _arg2, _arg3);
                this.m_transformDirty = true;
            };
        }
        public function translate(_arg1:Vector3):void{
            this.setPosition((this.m_position.x + _arg1.x), (this.m_position.y + _arg1.y), (this.m_position.z + _arg1.z));
        }
        public function setSize(_arg1:Number, _arg2:Number, _arg3:Number=0):void{
            if (((((!((this.m_size.x == _arg1))) || (!((this.m_size.y == _arg2))))) || (!((this.m_size.z == _arg3))))){
                this.m_size = new Vector3(_arg1, _arg2, _arg3);
                this.m_transformDirty = true;
            };
        }
        public function isAttached():Boolean{
            return (!((this.m_attachPosition == null)));
        }
        public function getAttachPosition():Vector3{
            return (this.m_attachPosition.clone());
        }
        public function getAttachSize():Vector3{
            return (this.m_attachSize.clone());
        }
        public function intersects(_arg1:PositionedObject):Boolean{
            var _local2:Vector3 = this.getPosition();
            var _local3:Vector3 = this.getEndPosition();
            var _local4:Vector3 = _arg1.getPosition();
            var _local5:Vector3 = _arg1.getEndPosition();
            var _local6:Boolean;
            if ((((((((((_local3.x <= _local4.x)) || ((_local2.x >= _local5.x)))) || ((_local3.y <= _local4.y)))) || ((_local2.y >= _local5.y)))) || (((((!((_local3.z == _local2.z))) && (!((_local4.z == _local5.z))))) && ((((_local3.z < _local4.z)) || ((_local2.z > _local5.z)))))))){
                _local6 = false;
            };
            return (_local6);
        }
        public function isCurrentPositionValid():Boolean{
            return (true);
        }
        public function getCursor():Class{
            return (null);
        }
        public function setHighlighted(_arg1:Boolean, _arg2:uint=0xFFAA00):void{
            if (this.m_displayObject){
                this.m_highlighted = _arg1;
                if (_arg1){
                    this.m_displayObject.filters = [new GlowFilter(_arg2, 1, 16, 16, 4)];
                } else {
                    this.m_displayObject.filters = [];
                };
            };
        }
        public function isHighlighted():Boolean{
            return (this.m_highlighted);
        }
        public function isInteractable():Boolean{
            return (((this.m_objectFlags & Constants.OBJECTFLAG_INTERACTIVE) > 0));
        }
        public function hasMouseOver():Boolean{
            return (false);
        }
        public function pickObject(_arg1:Point, _arg2:uint=0xFFFFFF, _arg3:uint=0):PositionedObject{
            var _local4:PositionedObject;
            if (((((this.isPickable()) && (this.checkObjectType(_arg2)))) && (this.checkObjectFlags(_arg3)))){
                if (((this.isVisible()) && (this.isPixelInside(_arg1)))){
                    _local4 = this.getReference();
                };
            };
            return (_local4);
        }
        public function drawDisplayObject():void{
        }
        public function createDisplayObject():DisplayObject{
            return (null);
        }
        public function updateDisplayObjectTransform():void{
        }
        public function deleteDisplayObject():void{
            if (this.m_displayObject != null){
                if (this.m_displayObject.parent != null){
                    this.m_displayObject.parent.removeChild(this.m_displayObject);
                };
                this.m_displayObject = null;
                this.m_displayObjectDirty = true;
            };
        }
        public function getDisplayObject():DisplayObject{
            return (this.m_displayObject);
        }
        public function isDisplayObjectDirty():Boolean{
            return (((this.m_displayObjectDirty) || ((this.m_displayObject == null))));
        }
        public function setDisplayObjectDirty(_arg1:Boolean):void{
            this.m_displayObjectDirty = _arg1;
        }
        public function getActualDisplayObjectSize():Vector2{
            var _local1:Vector2 = new Vector2();
            if (this.m_displayObject != null){
                _local1.x = this.m_displayObject.width;
                _local1.y = this.m_displayObject.height;
            };
            return (_local1);
        }

    }
}//package Engine.Classes 
